/*
* 收料单材料详情
* */

import 'package:center_beijing/api/material_science_api.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:center_beijing/widgets/custom_loading_widget.dart';
import 'package:center_beijing/widgets/imagesWatch_widget2.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';

class MaterialWarehousingDetail extends StatefulWidget {
  @override
  _MaterialWarehousingDetailState createState() =>
      _MaterialWarehousingDetailState();
}

class _MaterialWarehousingDetailState extends State<MaterialWarehousingDetail>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  CustomLoading loading = CustomLoading.withMessage('请稍候...');
  var pass = Get.arguments;
  var currentDetail = Map();

  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    this.getDetail();
  }

  @override
  void dispose() {
    _controller.dispose();
    loading.dismiss();
    super.dispose();
  }

  /*
  * 获取收料单详情
  * */
  getDetail() async {
    loading.show(delay: 30);
    var result = await getOmMaterialReceivedEntryEx({'id': pass['id']});
    loading.dismiss();
    if (result != null && result['hasError'] == null) {
      this.setState(() {
        currentDetail = result;
      });
    } else {
      Fluttertoast.showToast(msg: result['errorMessage']);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('材料详情'),
      ),
      body: Container(
        color: Styles.MainBackgroundColor,
        padding:
            EdgeInsets.fromLTRB(0, 0, 0, MediaQuery.of(context).padding.bottom),
        child: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text('所属单号 ${this.currentDetail['docNumber']}'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text('规格型号 ${this.currentDetail['specName']}'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text('计量单位 ${this.currentDetail['measureUnit']}'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text(
                    '数量 ${this.currentDetail['quantity'] != null ? this.currentDetail['quantity']['value'] : '--'}'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text(
                    '采购单价(含税) ${this.currentDetail['unitPrice'] != null ? this.currentDetail['unitPrice']['value'] : '--'}元'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text(
                    '采购单价(不含税) ${this.currentDetail['unitPriceExcludeTax'] != null ? this.currentDetail['unitPriceExcludeTax']['value'] : '--'}元'),
              ),

              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text(
                    '采购金额(含税) ${this.currentDetail['unitPrice'] != null ? (double.parse(this.currentDetail['unitPrice']['value'])*int.parse(this.currentDetail['quantity']['value'])).toStringAsFixed(2) : '--'}元'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text(
                    '采购金额(不含税) ${this.currentDetail['unitPriceExcludeTax'] != null ? (double.parse(this.currentDetail['unitPriceExcludeTax']['value'])*int.parse(this.currentDetail['quantity']['value'])).toString() : '--'}元'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text('入账金额 ${this.currentDetail['recordedAmount']['value']??'--'}元'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text('是否预收 ${this.currentDetail['receiveType']=='1'?'是':'否'}'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text('供货合同 ${this.currentDetail['contractNumber']}'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text('市场来源 ${this.currentDetail['marketSource']??'--'}'),
              ),
              Container(
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Text('备注 ${this.currentDetail['remark']}'),
              ),
              currentDetail['attachmentList'] != null &&
                      currentDetail['attachmentList'].length > 0
                  ? Container(
                      color: Colors.white,
                      padding: EdgeInsets.fromLTRB(
                          Styles.spacing16, 0, Styles.spacing16, 0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Container(
                            padding: EdgeInsets.fromLTRB(
                                0, Styles.spacing8, 0, Styles.spacing8),
                            child: Text(
                              '照片',
                              style: TextStyle(
                                  color: Styles.DetailColor,
                                  fontSize: Styles.NormalFont),
                            ),
                          ),
                          ImagesWatchWidget2(
                            photos: currentDetail['attachmentList']
                                .map<String>((image) {
                              return "${GlobalConfig.baseUrl}fs/irest/file/mps_fileTransferHandler/image?id=${image['atchId']}&ZJQFSESSION=${GlobalConfig.session}";
                            }).toList(),
                          )
                        ],
                      ),
                    )
                  : Container(),
            ],
          ),
        ),
      ),
    );
  }
}
